<include file="Public/header" title="添加礼品 - 企业安全应急响应与缺陷管理中心" links_status="open" links_color="#6164C1;"/>
<div class="main-content">
<div class="page-title">
<ol class="breadcrumb no-bg pl0">
<li>
<i class="icon-layers"></i> <a href="{:U('gifts/index')}">礼品列表</a>
</li>
<li>
<a href="javascript:;">添加礼品</a>
</li>
</ol>
</div>
    <form method="post" action="{:U('gifts/add')}">
        <div class="form-group">
            <label for="aa">礼品名称</label>
            <input type="text" name="title" class="form-control" placeholder="输入礼品名称...">
        </div>
		<div class="form-group">
            <label for="cc">礼品价格</label>
            <input type="text" name="price" class="form-control" placeholder="输入礼品价格...">
        </div>
		<div class="form-group">
            <label for="cc">礼品库存</label>
            <input type="text" name="stock" class="form-control" placeholder="输入礼品库存...">
        </div>
        <div class="form-group">
            <label for="post-cate">礼品分类 </label>
            <select name="category" class="form-control" style="width:100%;">
                <option value="cash">现金奖励</option>
			    <option value="digital">数码产品</option>
				<option value="book">专业书籍</option>
				<option value="culture">文化周边</option>
				<option value="others">其他礼品</option>
            </select>
        </div>
		<div class="form-group">
            <label for="post-cate">上架状态 </label>
            <select name="visible" class="form-control" style="width:100%;">
					<option value="0">上架</option>
					<option value="1">下架</option>
            </select>
        </div>
		<div class="form-group">
            <label for="page-title">礼品配图<small> (* 图片大小建议设置为 160*160)</small>: </label>
            <input id="giftImg" type="file" name="photo" onchange="submit_gift_picture();">
        </div>
		<div class="form-group">
            <label for="page-title">配图预览: </label>
			<br/>
            <img style="height:160px;width;160px;" id="figureurl" src="__PUBLIC__/Uploads/demo-gift.jpg">
			<input id="imgvalue" name="url" type="hidden" value="__PUBLIC__/Uploads/demo-gift.jpg">
        </div>
        <div class="form-group">
            <input type="hidden" name="token" value="{:session('token')}"/>
			<button type="submit" class="btn btn-default">提交</button>
        </div>
    </form>
</div>
<script>
		function submit_gift_picture(){
						$("#imgWait").show();
						var formData = new FormData();
						formData.append("photo", document.getElementById("giftImg").files[0]);   
						$.ajax({
							url: "__ROOT__/admin.php?m=Admin&c=gifts&a=upload",
							type: "POST",
							data: formData,
							/**
							*必须false才会自动加上正确的Content-Type
							*/
							contentType: false,
							/**
							* 必须false才会避开jQuery对 formdata 的默认处理
							* XMLHttpRequest会对 formdata 进行正确的处理
							*/
							processData: false,
							success: function (data) {
								if (data.code == "200") {
									var figureurl = "__PUBLIC__/Uploads/" + data.savepath;
									$("#figureurl").attr("src",figureurl);
									$("#imgvalue").attr("value",figureurl);
								}else{
									alert('上传失败请重试');
									//$("#upload_tips").css("display","block");
								}
								//$("#imgWait").hide();
							},
							error: function () {
								alert('上传失败请重试');
								//$("#upload_tips").css("display","block");
								//$("#imgWait").hide();
							}
						});
		}
</script>
<include file="Public/footer" />